var id = getvl("id");

if(id != '') {
	//商品详情
	goodsQiuGouDetailById(id);

}

function goodsQiuGouDetailById(id) {

	$("#photoDetail").html(""); //放大镜
	$("#qiugoudetail").html(""); //详细信息
	$("#qiugoumiaoshu").html(""); //描述
	$.ajax({
		url: urlcore + "/api/wantBuy/selectOne?id=" + id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var da = data.data;

				var imgs = '';
				var imgs1=isHasImg(da.coverUrl);
				//var imgs1 = '';
				if(da.goodsUrl != null) {
						var goodsUrlArr = da.goodsUrl.split("***");
						$.each(goodsUrlArr, function(i, val) {
							val=isHasImg(val);
							imgs += '<li>' +
								'<a href="' + val + '"><img class="goodsUrlImg" src="' + val + '" alt="Image Name" /></a>' +
								'</li>';
						});
				} 
				imgs += '<li>' +
						'<a href="' + imgs1 + '"><img class="goodsUrlImg" src="' + imgs1 + '" alt="Image Name" /></a>' +
						'</li>';
				 
				var photoDetail =
					'<div class="examples_bg">' +
					'		                <div class="examples_image">' +
					'		                    <img class="coverUrlImg" src="' + imgs1 + '" alt="" />' +
					'		                    <div class="desc">' +
					'		                        <a href="#" class="collapse"></a>' +
					'		                        <div class="block"></div>' +
					'		                    </div>' +
					'		                </div>' +
					'		                <div class="mune_thumb">' +
					'<ul>' + imgs + '</ul>' +
					'</div>' +
					'</div>';
				$("#photoDetail").append(photoDetail);
				
				//Banner 轮播图样式
				$(document).ready(function() {

					//Show Banner
					$(".examples_image .desc").show(); //Show Banner
					$(".examples_image .block").animate({ opacity: 0.85 }, 1); //Set Opacity

					//Click and Hover events for thumbnail list
					$(".mune_thumb ul li:first").addClass('active');
					$(".mune_thumb ul li").hover(function() {
						//Set Variables
						var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
						var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
						var imgDesc = $(this).find('.block').html(); //Get HTML of block
						var imgDescHeight = $(".examples_image").find('.block').height(); //Calculate height of block	

						if($(this).is(".active")) { //If it's already active, then...
							return false; // Don't click through
						} else {
							//Animate			
							$(".examples_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250, function() {
								$(".examples_image .block").html(imgDesc).animate({ opacity: 0.85, marginBottom: "0" }, 250);
								$(".examples_image img").attr({ src: imgTitle, alt: imgAlt });
							});
						}

						$(".mune_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
						$(this).addClass('active'); //add class of 'active' on this list only
						return false;

					}).hover(function() {
						$(this).addClass('hover');
					}, function() {
						$(this).removeClass('hover');
					});

					//Toggle
					$("a.collapse").click(function() {
						$(".examples_image .block").slideToggle();
						$("a.collapse").toggleClass("show");
					});

				});

				var qq = da.qq == null ? '未填写' : da.qq;
				var colourName=da.colourName==null?'暂无':da.colourName;
                var sizeName=da.sizeName==null?'暂无':da.sizeName;
                var tradeAreaName=da.tradeAreaName==null?"暂无":da.tradeAreaName;
                var wantBuyTypeName=da.wantBuyTypeName==null?"暂无":da.wantBuyTypeName;
                var contactName=da.contactName==null?"暂无":da.contactName;
                var phone=da.phone==null?"暂无":da.phone;
                var goodsNum=da.goodsNum==null?0:da.goodsNum;
                
				/*       	var colorName = '';
					 
						var colourNameArr = da.colourName.split("、");
							$.each(colourNameArr, function(i, val1) {
								colorName += '<em>' + val1 + '</em>';
							});

				    	
					    var sizeName = '';
					 
						var sizeNameArr = da.sizeName.split("、");
						$.each(sizeNameArr, function(i, val2) {
							sizeName += '<em>' + val2 + '</em>';
						}); */

				var qiugoudetail =
					'<ul>' +
					'					<li class="clearfix">' +
					'						<span>发布商圈：</span>' +
					'						<div>' + tradeAreaName + '</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;类：</span>' +
					'						<div>' + wantBuyTypeName + '</div>' +
					'					</li>' +
					'				</ul>' +
					'				<ul>' +
					'					<li class="clearfix">' +
					'						<span>联&nbsp;&nbsp;系&nbsp;人：</span>' +
					'						<div>' + contactName + '</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>电话联系：</span>' +
					'						<div>' + phone + '</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span style="text-align: right;">QQ：</span>' +
					'						<div>' + qq + '</div>' +
					'					</li>' +
					'				</ul>' +
					'				<ul>' +
					'					<li class="clearfix">' +
					'						<span>所需数量：</span>' +
					'						<div>' +
					'							<span>' + goodsNum + ' 件</span>' +
					'						</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>颜&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</span>' +
					'						<div>' + colourName +
					'						</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>尺&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;寸：</span>' +
					'						<div>' + sizeName +
					'						</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>求购时间：</span>' +
					'						<div>' + da.gmtDatetime + '</div>' +
					'					</li>' +
					'					<li class="clearfix">' +
					'						<span>浏览次数：</span>' +
					'						<div>225</div>' +
					'					</li>' +
					'				</ul>' +
					'				<div class="qiugou_siliao public-chat"><img src="images/siliao.png" />私聊</div>';

				$("#qiugoudetail").append(qiugoudetail);
				
							//弹窗二维码
				$(function(){
					//弹出
					$('.public-chat').on('click',function(){		
			        	$(".public_simi_bg").fadeIn();
					});	
				    $(".public_simi_bg").on('click',function(){
				        $(".public_simi_bg").fadeOut();
				    }) 
				});
				
				var goodsDescribe=da.goodsDescribe==null?"暂无":da.goodsDescribe;
				
				var photos1 = '';
				if(da.goodsUrl!=null){
					var photoArr1 = da.goodsUrl.split("***");
					$.each(photoArr1, function(i, val) {
						val=isHasImg(val);
						photos1 += '<img src="' + val + '" alt="Image Name" /><br/><br/>';
					});
				}
				photos1 += '<img src="' + isHasImg(da.coverUrl) + '" alt="Image Name" /><br/><br/>';
				
				
				//求购描述
				var simple =
					'<h5>商品详情</h5>' +
					'<p>' + goodsDescribe + '</p>' +
					photos1;

				$("#qiugoumiaoshu").append(simple);

				newGoods(2);
				huoGoods(3);

			}
			$(function(){
				var imgList = document.getElementsByClassName("coverUrlImg");  
			    var w=450;
			    var h=450;
			    for(var i=0;i<imgList.length;i++){
			        if(imgList[i].width>w || imgList[i].height>h){  
			            imgList[i].width = w;  
			            imgList[i].heigth = h;  
			        }  
			    }  
			    
			    var imgList1 = document.getElementsByClassName("goodsUrlImg");  
			    var w1=80;
			    var h1=80;
			    for(var i=0;i<imgList1.length;i++){
			        if(imgList1[i].width>w1 || imgList1[i].height>h1){  
			            imgList1[i].width = w1;  
			            imgList1[i].heigth = h1;  
			        }  
			    }  
			})
		},
		error: function() {
			layer.alert("error");
		}
	});
}

function newGoods(sort) {

	$("#newQiugou").html("");
	$.ajax({
		url: urlcore + "/api/wantBuy/selectList?sort=" + sort,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				$.each(data.data.list, function(i, n) {
					
					var coverUrl=n.coverUrl==null?'http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/default.png':n.coverUrl;
					coverUrl=isHasImg(coverUrl);
					var thislist =
						'<a href="4.1.0qiugou_detail.html?id=' + n.id + '">' +
						'<img class="remenImg" src="' + coverUrl + '" />' +
						'</a>';

					$('#newQiugou').append(thislist);
				});
			}
			
			$(function(){
				var imgList = document.getElementsByClassName("remenImg");
				var w=104;
			    var h=104;
			    for(var i=0;i<imgList.length;i++){
			        if(imgList[i].width>w || imgList[i].height>h){  
			            imgList[i].width = w;  
			            imgList[i].heigth = h;  
			        }  
			    }  
			})
		},
		error: function() {
			layer.alert("error");
		}
	});
}

function huoGoods(sort) {

	$("#huoQiugou").html("");
	$.ajax({
		url: urlcore + "/api/wantBuy/selectList?sort=" + sort,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				$.each(data.data.list, function(i, n) {
					
					var coverUrl=n.coverUrl==null?'http://app.jiagangwangluo.com:8080/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/default.png':n.coverUrl;
					coverUrl=isHasImg(coverUrl);
					var thislist =
						'<a href="4.1.0qiugou_detail.html?id=' + n.id + '">' +
						'<img class="huoGoodsImg" src="' + coverUrl + '" />' +
						'</a>';

					$('#huoQiugou').append(thislist);
				});
			}
			
			$(function(){
				var imgList = document.getElementsByClassName("huoGoodsImg");
				var w=104;
			    var h=104;
			    for(var i=0;i<imgList.length;i++){
			        if(imgList[i].width>w || imgList[i].height>h){  
			            imgList[i].width = w;  
			            imgList[i].heigth = h;  
			        }  
			    }  
			})
		},
		error: function() {
			layer.alert("error");
		}
	});
}